package com.example.goods_service.service;

import com.example.goods_service.dao.GoodsDao_zhoufuyu;
import com.example.goods_service.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl_zhoufuyu implements GoodsService_zhoufuyu {
    @Autowired
    GoodsDao_zhoufuyu goodsDao_zhoufuyu;

    @Override
    public String selallpeizhi(int id) {
        T_commodity x = goodsDao_zhoufuyu.selcom_id(id);
        System.out.println(x.getCategory_id());
        if (x.getCategory_id() != 0) {
            T_commodity_category a = goodsDao_zhoufuyu.sel_smallfenlei(x.getCategory_id());
            T_commodity_category b = goodsDao_zhoufuyu.sel_middlefenlei(x.getCategory_id());
            T_commodity_category c = goodsDao_zhoufuyu.sel_bigfenlei(x.getCategory_id());
            return c.getName() + b.getName() + a.getName();
        }
        return null;
    }

   @Override
   public List<T_attribute> sel_attribute(int id) {
       return goodsDao_zhoufuyu.sel_attribute(id);
   }

    @Override
    public List<T_config> sel_config(int id) {
        return goodsDao_zhoufuyu.sel_config(id);
    }

    @Override
    public int upcom_pic(int picture_id, int goodsid) {
        return goodsDao_zhoufuyu.upcom_pic(picture_id,goodsid);
    }

    @Override
    public int addpic(String picture_path_name) {
        return goodsDao_zhoufuyu.addpic(picture_path_name);
    }


    @Override
    public int selpicid(String picture_path_name) {
        return goodsDao_zhoufuyu.selpicid(picture_path_name);
    }


    @Override
    public List<T_com_com_all> selbyid(int id) {
        return goodsDao_zhoufuyu.selbyid(id);
    }

    @Override
    public int upgoods(String commodity_name, String commodity_description, double commodity_price, int id) {
        return goodsDao_zhoufuyu.upgoods(commodity_name, commodity_description, commodity_price, id);
    }

    @Override
    public int upxl(int id, int shuliang) {
        int xl = goodsDao_zhoufuyu.selxl(id).getSales_volume();
        return goodsDao_zhoufuyu.upxl(id, xl+shuliang);
    }

    @Override
    public int updategg(String attribute, double price, int stock, int id) {
        return goodsDao_zhoufuyu.updategg(attribute, price, stock, id);
    }

    @Override
    public int upkc(int commodity_id, String attribute, int shuliang) {
         int kc= goodsDao_zhoufuyu.selkc(commodity_id, attribute).getStock();

        return goodsDao_zhoufuyu.upkc(commodity_id, attribute, kc-shuliang);
    }
}
